package cn.wlinker.video.monitor.brand.hikversion.create.net;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.log.StaticLog;
import cn.wlinker.video.monitor.utils.CommonKitUtils;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.Getter;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;

/**
 * 海康网络设备工具类
 *
 * @author gxsjx
 * @version 1.0
 * @date 2025/5/3
 * Copyright © wlinker.cn
 */
public class  HCNetTools {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    static HCNetSDK hCNetSDK;

    //海康播放库(SDK里的PlayCtrl不是此处的PlayCtrl)
    //static PlayCtrl playControl = PlayCtrl.INSTANCE;

    private HCNetSDK.NET_DVR_WORKSTATE_V30 m_strWorkState;
    private HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo;//设备信息
    private HCNetSDK.NET_DVR_IPPARACFG m_strIpparaCfg;//IP参数
    private HCNetSDK.NET_DVR_CLIENTINFO m_strClientInfo;//用户参数

    private boolean bRealPlay;//是否在预览.
    private String m_sDeviceIP;//已登录设备的IP地址

    @Getter
    private int lUserID;//用户句柄
    private int loadHandle;//下载句柄
    private int lPreviewHandle;//预览句柄
    private IntByReference m_lPort;//回调预览时播放库端口指针
    private IntByReference m_err;//错误号

    // 在服务类中定义队列
    static int iPlayBack;
    static MyPlayDataCallBack playBackCallBack; //回放码流回调
    @Getter
    Timer Playbacktimer;//回放用定时器
    static boolean palybackFlay = false;
    PipedOutputStream pipeOutput;

    public HCNetTools() {
        lUserID = -1;
        lPreviewHandle = -1;
        m_lPort = new IntByReference(-1);
        m_err = new IntByReference(-1);
    }

    /**
     * 初始化资源
     */
    public synchronized static void init() {
        if (hCNetSDK != null) {
            return;
        }
        synchronized (HCNetSDK.class) {
            if (hCNetSDK != null) {
                return;
            }
            hCNetSDK = (HCNetSDK) Native.loadLibrary(CommonKitUtils.getLibPath(), HCNetSDK.class);
        }
        boolean b = hCNetSDK.NET_DVR_Init();
        // 设置连接超时（单位：毫秒）
        hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
        // 启用重连
        hCNetSDK.NET_DVR_SetReconnect(10000, true);
        if (!b) {
            //初始化失败
            //throw new RuntimeException("初始化失败");
            StaticLog.error("初始化失败");
        } else {
            StaticLog.info("初始化成功");
        }
    }

    /**
     * 释放资源
     */
    public synchronized static void clearUp() {
        HCNetTools.hCNetSDK.NET_DVR_Cleanup();
        hCNetSDK = null;
    }

    /**
     * 设备注册
     *
     * @param name     设备用户名
     * @param password 设备登录密码
     * @param ip       IP地址
     * @param port     端口
     * @return 结果
     */
    public synchronized int deviceLogin(String name, String password, String ip, Integer port) {

        if (bRealPlay) {//判断当前是否在预览
            return 2;//"注册新用户请先停止当前预览";
        }
        if (lUserID > -1) {//先注销,在登录
            hCNetSDK.NET_DVR_Logout_V30(lUserID);
            lUserID = -1;
        }
        //注册(既登录设备)开始
        m_sDeviceIP = ip;
        short iPort = port.shortValue();
        m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();//获取设备参数结构
        lUserID = hCNetSDK.NET_DVR_Login_V30(ip, iPort, name, password, m_strDeviceInfo);//登录设备
        long userID = lUserID;
        if (userID == -1) {
            int iErr = hCNetSDK.NET_DVR_GetLastError();
            System.out.println("：注册失败,错误号：" + iErr);
            System.out.println(hCNetSDK.NET_DVR_GetErrorMsg(m_err));
            m_sDeviceIP = "";//登录未成功,IP置为空
            return 3;//"注册失败";
        }
        return 0;
    }

    /**
     * 注销登陆
     */
    public synchronized void deviceLogout() {

        if(getPlaybacktimer() != null){
            getPlaybacktimer().cancel();
        }

        if(iPlayBack>-1){
            hCNetSDK.NET_DVR_StopPlayBack(iPlayBack);
        }

        //如果在预览,先停止预览, 释放句柄
        if (lPreviewHandle > -1) {
            hCNetSDK.NET_DVR_StopRealPlay(lPreviewHandle);
        }

        //如果已经注册,注销
        if (lUserID > -1) {
            hCNetSDK.NET_DVR_Logout_V30(lUserID);
        }

    }

    /**
     * 获取设备通道
     */
    public synchronized List<String> getChannelNumber() {
        List<String> channelList = new ArrayList<>();

        IntByReference ibrBytesReturned = new IntByReference(0);//获取IP接入配置参数
        boolean bRet;
        m_strIpparaCfg = new HCNetSDK.NET_DVR_IPPARACFG();
        m_strIpparaCfg.write();
        Pointer lpIpParaConfig = m_strIpparaCfg.getPointer();
        bRet = (m_strDeviceInfo.byIPChanNum != 0);

        String devices;
        if (!bRet) {
            //设备不支持,则表示没有IP通道
            for (int iChannum = 0; iChannum < m_strDeviceInfo.byChanNum; iChannum++) {
                devices = "Camera" + (iChannum + m_strDeviceInfo.byStartChan);
                channelList.add(devices);
            }
        } else {
            //设备支持IP通道
            boolean ok = hCNetSDK.NET_DVR_GetDVRConfig(lUserID, HCNetSDK.NET_DVR_GET_IPPARACFG, 0, lpIpParaConfig, m_strIpparaCfg.size(), ibrBytesReturned);
            if (!ok) {
                String err = hCNetSDK.NET_DVR_GetErrorMsg(m_err);
                logger.info("获取配置失败：{},{}", m_err.getValue(), err);
            }
            m_strIpparaCfg.read();

            for (int iChannum = 0; iChannum < m_strDeviceInfo.byChanNum; iChannum++) {
                if (m_strIpparaCfg.byAnalogChanEnable[iChannum] == 1) {
                    devices = "Camera" + (iChannum + m_strDeviceInfo.byStartChan);
                    channelList.add(devices);
                }
            }

            for (int iChannum = 0; iChannum < HCNetSDK.MAX_IP_CHANNEL; iChannum++) {
                if (m_strIpparaCfg.struIPChanInfo[iChannum].byEnable == 1) {
//                    devices = "IP" + (hCNetSDK.NET_DVR_SDKChannelToISAPI(lUserID, iChannum + m_strDeviceInfo.byStartDChan, true));
                    devices = "IP";
                    String channelIP = (new String(m_strIpparaCfg.struIPDevInfo[iChannum].struIP.sIpV4));
                    channelIP = channelIP.trim();
                    devices = devices + "," + channelIP;
                    channelList.add(devices);
                }
            }
        }

        return channelList;
    }



    //获取IP通道
    public synchronized Map<Integer, Pair<String,Boolean>> getIPChannelInfo() {
        Map<Integer, Pair<String,Boolean>> channelMap = new HashMap<>(8);
        IntByReference ibrBytesReturned = new IntByReference(0);//获取IP接入配置参数
        HCNetSDK.NET_DVR_IPPARACFG_V40 m_strIpparaCfg = new HCNetSDK.NET_DVR_IPPARACFG_V40();
        m_strIpparaCfg.write();
        //lpIpParaConfig 接收数据的缓冲指针
        Pointer lpIpParaConfig = m_strIpparaCfg.getPointer();
        boolean bRet = hCNetSDK.NET_DVR_GetDVRConfig(lUserID, HCNetSDK.NET_DVR_GET_IPPARACFG_V40, 0, lpIpParaConfig, m_strIpparaCfg.size(), ibrBytesReturned);
        m_strIpparaCfg.read();
        //System.out.println("起始数字通道号：" + m_strIpparaCfg.dwStartDChan);

        for (int iChannum = 0; iChannum < m_strIpparaCfg.dwDChanNum; iChannum++) {
            int channum = iChannum + m_strIpparaCfg.dwStartDChan;
            m_strIpparaCfg.struStreamMode[iChannum].read();
            if (m_strIpparaCfg.struStreamMode[iChannum].byGetStreamType == 0) {
                m_strIpparaCfg.struStreamMode[iChannum].uGetStream.setType(HCNetSDK.NET_DVR_IPCHANINFO.class);
                m_strIpparaCfg.struStreamMode[iChannum].uGetStream.struChanInfo.read();
                String channelIp = null;
                boolean status = false;
                if (m_strIpparaCfg.struStreamMode[iChannum].uGetStream.struChanInfo.byEnable == 1) {
                    channelIp = (new String(m_strIpparaCfg.struIPDevInfo[iChannum].struIP.sIpV4));
                    channelIp = channelIp.trim();
                    status = true;
                }
                Pair<String, Boolean> pair = new Pair<>(channelIp, status);
                channelMap.put(channum, pair);
            }
        }
        return channelMap;
    }

    /**
     * 抓拍图片
     *
     * @param channel 通道号
     */
    public synchronized boolean getDVRPic(Integer channel, String path) {
        HCNetSDK.NET_DVR_WORKSTATE_V30 devwork = new HCNetSDK.NET_DVR_WORKSTATE_V30();
        if (!hCNetSDK.NET_DVR_GetDVRWorkState_V30(lUserID, devwork)) {
            // 返回Boolean值，判断是否获取设备能力
            logger.info("hksdk(抓图)-返回设备状态失败");
        }
        //图片质量
        HCNetSDK.NET_DVR_JPEGPARA jpeg = new HCNetSDK.NET_DVR_JPEGPARA();
        //设置图片分辨率
        jpeg.wPicSize = 0;
        //设置图片质量
        jpeg.wPicQuality = 0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileNameString = "D:/CapturePicture/" + sdf.format(DateUtil.date()) + ".jpg";
        boolean ok = hCNetSDK.NET_DVR_CaptureJPEGPicture(lUserID, channel, jpeg, fileNameString.getBytes());
        if (ok) {
            logger.info("hksdk(抓图)-结果状态值(0表示成功):{}", hCNetSDK.NET_DVR_GetLastError());
        } else {
            String err = hCNetSDK.NET_DVR_GetErrorMsg(m_err);
            logger.info("hksdk(抓图)-抓取失败,错误码:{},{}", m_err.getValue(), err);
        }
        return ok;
    }

    /**
     * 下载录像
     *
     * @return boolean
     */
    @SneakyThrows
    public synchronized boolean downloadBack(LocalDateTime startTime, LocalDateTime endTime, String filePath, int channel) {
        loadHandle = -1;
        loadHandle = hCNetSDK.NET_DVR_GetFileByTime(lUserID, channel, getHkTime(startTime), getHkTime(endTime), filePath);
        if (loadHandle >= 0) {
            //开始下载
            boolean downloadFlag = hCNetSDK.NET_DVR_PlayBackControl(loadHandle, HCNetSDK.NET_DVR_PLAYSTART, 0, null);
            int tmp = -1;
            IntByReference pos = new IntByReference(0);
            while (loadHandle >= 0) {
                boolean backFlag = hCNetSDK.NET_DVR_PlayBackControl(loadHandle, HCNetSDK.NET_DVR_PLAYGETPOS, 0, pos);
                if (!backFlag) {//防止单个线程死循环
                    return downloadFlag;
                }
                int produce = pos.getValue();
                if ((produce % 10) == 0 && tmp != produce) {//输出进度
                    tmp = produce;
                    logger.info("视频下载进度:=={}%", produce);
                }
                if (produce == 100) {//下载成功
                    hCNetSDK.NET_DVR_StopGetFile(loadHandle);
                    loadHandle = -1;
                    String err = hCNetSDK.NET_DVR_GetErrorMsg(m_err);
                    logger.info("下载结束,last error: {},{}", m_err.getValue(), err);
                    return true;
                }
                if (produce > 100) {//下载失败
                    hCNetSDK.NET_DVR_StopGetFile(loadHandle);
                    loadHandle = -1;
                    String err = hCNetSDK.NET_DVR_GetErrorMsg(m_err);
                    logger.warn("下载异常终止!错误原因:{},{}", m_err.getValue(), err);
                    return false;
                }
                Thread.sleep(500);
            }
            String err = hCNetSDK.NET_DVR_GetErrorMsg(m_err);
            logger.warn("下载异常终止!错误原因:{},{}", m_err.getValue(), err);
        } else {
            String err = hCNetSDK.NET_DVR_GetErrorMsg(m_err);
            logger.warn("获取录像文件错误!错误原因:{},{}", m_err.getValue(), err);
        }
        return false;
    }


    /**
     * 按时间回放录像
     * @param lChannel 通道号
     */
    public void playBackByTime(LocalDateTime startTime, LocalDateTime endTime, int lChannel,Thread thread,PipedInputStream inputStream)
    {
        playBackCallBack = null;
        try {
            pipeOutput = new PipedOutputStream(inputStream);
        } catch (Exception e) {
            StaticLog.error(e);
        }
        HCNetSDK.NET_DVR_VOD_PARA net_dvr_vod_para = new HCNetSDK.NET_DVR_VOD_PARA();
        net_dvr_vod_para.dwSize = net_dvr_vod_para.size();
        net_dvr_vod_para.struIDInfo.dwChannel = lChannel; //通道号
        //开始时间
        net_dvr_vod_para.struBeginTime = getHkTime(startTime);
        //停止时间
        net_dvr_vod_para.struEndTime = getHkTime(endTime);
        net_dvr_vod_para.hWnd = null; // 回放的窗口句柄，若置为空，SDK仍能收到码流数据，但不解码显示
        net_dvr_vod_para.write();
        iPlayBack = hCNetSDK.NET_DVR_PlayBackByTime_V40(lUserID, net_dvr_vod_para);
        if (iPlayBack <= -1) {
            System.out.println("按时间回放失败，错误码为" + hCNetSDK.NET_DVR_GetLastError());
            palybackFlay = true;
            return;
        }
        //开启取流
        IntByReference intP = new IntByReference(54962 * 1024);
        IntByReference intInlen1 = new IntByReference(0);
        boolean bCrtl = hCNetSDK.NET_DVR_PlayBackControl_V40(iPlayBack, HCNetSDK.NET_DVR_PLAYSTART, Pointer.NULL, 0, Pointer.NULL, intInlen1);
        if (bCrtl == false) {
            System.out.println("NET_DVR_PLAYSTART失败，错误码为" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }
        //切换倒放
//        IntByReference intInlen2=new IntByReference(0);
//        boolean bCrtl2=hCNetSDK.NET_DVR_PlayBackControl_V40(iPlayBack, HCNetSDK.NET_DVR_PLAY_REVERSE, Pointer.NULL, 0, Pointer.NULL,intInlen2);
//        if (bCrtl2==false)
//        {
//            System.out.println("NET_DVR_PLAY_REVERSE失败，错误码为" + hCNetSDK.NET_DVR_GetLastError());
//            return;
//        }
        playBackCallBack = new MyPlayDataCallBack(thread,pipeOutput);
        boolean bRet = hCNetSDK.NET_DVR_SetPlayDataCallBack(iPlayBack, playBackCallBack, Pointer.NULL);
        //开始计时器
//        //新建定时器
//        Playbacktimer = new Timer();
//        //0秒后开始响应函数
//        Playbacktimer.schedule(new PlaybackTask(), 0, 5000);
        return;
    }

    /**
     * 按时间回放进度获取定时器
     */
    class PlaybackTask extends TimerTask
    {
        //定时器函数
        @Override
        public void run()
        {
            IntByReference nPos = new IntByReference(0);
            logger.info("iPlayBack "+iPlayBack);
            boolean bret=hCNetSDK.NET_DVR_PlayBackControl(iPlayBack, HCNetSDK.NET_DVR_PLAYGETPOS, 0, nPos);
            if (bret)
            {
                logger.info("回放进度" + nPos.getValue());
            }
            else
            {
                logger.info("获取回放进度失败");
            }
            if (nPos.getValue() > 100)
            {
                hCNetSDK.NET_DVR_StopPlayBack(iPlayBack);
                if (pipeOutput != null) {
                    try {
                        pipeOutput.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                palybackFlay = true;
                logger.error("由于网络原因或DVR忙,回放异常终止!");
                return;
            }
            if (nPos.getValue() == 100)
            {
                hCNetSDK.NET_DVR_StopPlayBack(iPlayBack);
                if (pipeOutput != null) {
                    try {
                        pipeOutput.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                palybackFlay = true;
                logger.info("按时间回放结束");
                // 任务完成后，取消定时器
                // 取消任务，防止再次执行
                this.cancel();
                // 取消定时器
                if (Playbacktimer != null) {
                    Playbacktimer.cancel();
                }
            }
            return;
        }
    }

     class MyPlayDataCallBack implements HCNetSDK.FPlayDataCallBack{

        private final Thread thread;

        private boolean flag;

        private final PipedOutputStream pipeOutput;

        private AtomicInteger atomicInteger = new AtomicInteger(0);

        public MyPlayDataCallBack(Thread thread,PipedOutputStream pipeOutput)
        {
            this.thread = thread;
            this.flag = false;
            this.pipeOutput = pipeOutput;
        }

        public void invoke(int lPlayHandle, int dwDataType, Pointer pBuffer, int dwBufSize, int dwUser) {
            //System.out.println("回放码流回调...");
            //将设备发送过来的回放码流数据写入文件
            //StaticLog.info("回放码流回调次数:{}",atomicInteger.addAndGet(1));
            long offset = 0;
            ByteBuffer buffers = pBuffer.getByteBuffer(offset, dwBufSize);
            byte[] bytes = new byte[dwBufSize];
            buffers.rewind();
            buffers.get(bytes);
            try {
                this.pipeOutput.write(bytes);
                if(atomicInteger.addAndGet(1) % 50 == 0){
                    int i = atomicInteger.get() / 50;
//                    StaticLog.info("{},刷出通道：{}",atomicInteger.get(), i);
                    this.pipeOutput.flush();
                    if(i == 1){
                        LockSupport.unpark(thread);
                    }
                }
            } catch (IOException e) {
                stopPlayback();
                getPlaybacktimer().cancel();
                StaticLog.error(e,e.getLocalizedMessage());
            }
//            if (!dataQueue.offer(bytes)) {
//                System.err.println("队列已满，丢弃数据包");
//            }

            //播放库解码
/*            switch (dwDataType) {
                case HCNetSDK.NET_DVR_SYSHEAD: //系统头
                    if (!playControl.PlayM4_GetPort(m_lPort)) //获取播放库未使用的通道号
                    {
                        break;
                    }
                    if (dwBufSize > 0) {
                        if (!playControl.PlayM4_SetStreamOpenMode(m_lPort.getValue(), PlayCtrl.STREAME_REALTIME))  //设置实时流播放模式
                        {
                            break;
                        }
                        if (!playControl.PlayM4_OpenStream(m_lPort.getValue(), pBuffer, dwBufSize, 1024 * 1024)) //打开流接口
                        {
                            break;
                        }
                        if (!playControl.PlayM4_Play(m_lPort.getValue(), null)) //播放开始
                        {
                            break;
                        }

                    }
                case HCNetSDK.NET_DVR_STREAMDATA:   //码流数据
                    if ((dwBufSize > 0) && (m_lPort.getValue() != -1)) {
                        if (!playControl.PlayM4_InputData(m_lPort.getValue(), pBuffer, dwBufSize))  //输入流数据
                        {
                            break;
                        }
                    }
            }*/

        }

    }

    public void stopPlayback() {
        // 停止播放（清空内部缓存）
        // 发送自定义命令清空缓冲
        hCNetSDK.NET_DVR_PlayBackControl_V40(iPlayBack, HCNetSDK.NET_DVR_PLAYSTOP, Pointer.NULL, 0,Pointer.NULL,null);
        hCNetSDK.NET_DVR_PlayBackControl_V40(iPlayBack,HCNetSDK.NET_DVR_PLAYSTOP, Pointer.NULL, 0,Pointer.NULL,null);
        hCNetSDK.NET_DVR_StopPlayBack(iPlayBack);
        hCNetSDK.NET_DVR_Logout(lUserID);
    }

    /**
     * 获取录像文件信息
     *
     * @Return：
     */
    public List<HashMap<String, String>> getVideoFileList(LocalDateTime startTime, LocalDateTime endTime, int channel) {
        List<HashMap<String, String>> fileList = new ArrayList<>();

        // 搜索条件
        HCNetSDK.NET_DVR_FILECOND m_strFilecond = new HCNetSDK.NET_DVR_FILECOND();

        m_strFilecond.struStartTime = getHkTime(startTime);
        m_strFilecond.struStopTime = getHkTime(endTime);
        m_strFilecond.lChannel = channel;//通道号

        int lFindFile = hCNetSDK.NET_DVR_FindFile_V30(lUserID, m_strFilecond);
        HCNetSDK.NET_DVR_FINDDATA_V30 strFile;
        if (lFindFile < 0) {
            String err = hCNetSDK.NET_DVR_GetErrorMsg(m_err);
            logger.warn("获取录像文件错误!错误原因:{},{}", m_err.getValue(), err);
            return null;
        }
        int lnext;
        strFile = new HCNetSDK.NET_DVR_FINDDATA_V30();
        HashMap<String, String> map = new HashMap<>();
        boolean flag = true;
        while (flag) {
            lnext = hCNetSDK.NET_DVR_FindNextFile_V30(lFindFile, strFile);
            if (lnext == HCNetSDK.NET_DVR_FILE_SUCCESS) {
                //搜索成功
                //添加文件名信息
                String[] s = new String[2];
                s = new String(strFile.sFileName).split("\0", 2);
                map.put("fileName:", s[0]);

                int iTemp;
                String MyString;
                if (strFile.dwFileSize < 1024 * 1024) {
                    iTemp = (strFile.dwFileSize) / (1024);
                    MyString = iTemp + "K";
                } else {
                    iTemp = (strFile.dwFileSize) / (1024 * 1024);
                    MyString = iTemp + "M   ";
                    iTemp = ((strFile.dwFileSize) % (1024 * 1024)) / (1204);
                    MyString = MyString + iTemp + "K";
                }
                map.put("fileSize", MyString);                      //添加文件大小信息
                map.put("struStartTime", strFile.struStartTime.toStringTime());                      //添加开始时间信息
                map.put("struStopTime", strFile.struStopTime.toStringTime());                      //添加结束时间信息
                fileList.add(map);
            } else {
                if (lnext == HCNetSDK.NET_DVR_ISFINDING) {//搜索中
                    //System.out.println("搜索中");
                    continue;
                } else {
                    flag = false;
                    if (lnext == HCNetSDK.NET_DVR_FILE_NOFIND) {
                        //flag=false;
                    } else {
                        //flag=false;
                        System.out.println("搜索文件结束");
                        boolean flag2 = hCNetSDK.NET_DVR_FindClose_V30(lFindFile);
                        if (!flag2) {
                            System.out.println("结束搜索失败");
                        }
                    }
                }
            }
        }
        return fileList;
    }

    /**
     * 获取海康录像机格式的时间
     *
     * @param time
     * @return
     */
    public HCNetSDK.NET_DVR_TIME getHkTime(LocalDateTime time) {
        HCNetSDK.NET_DVR_TIME structTime = new HCNetSDK.NET_DVR_TIME();

        String str = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss").format(time);
        String[] times = str.split("-");
        structTime.dwYear = Integer.parseInt(times[0]);
        structTime.dwMonth = Integer.parseInt(times[1]);
        structTime.dwDay = Integer.parseInt(times[2]);
        structTime.dwHour = Integer.parseInt(times[3]);
        structTime.dwMinute = Integer.parseInt(times[4]);
        structTime.dwSecond = Integer.parseInt(times[5]);
        return structTime;
    }

}
